﻿using B.S.Database.Domain.Entity;
using B.S.Database.ErrorCode;
using B.S.Database.Interface.Interface;
using B.S.Database.Write.Api.Application.Commands.Breeding;
using MediatR;
using NuGet.Protocol.Plugins;

namespace B.S.Database.Write.Api.Application.CommandHandler.Breeding
{
    public class ImmuneXiugaiCommandHandler : IRequestHandler<ImmuneXiugaiCommands, Apiresult<object>>
    {
        private readonly IBaseResotity<Immune_Infomation> immuneRepo;

        public ImmuneXiugaiCommandHandler(IBaseResotity<Immune_Infomation> ImmuneRepo)
        {
            immuneRepo = ImmuneRepo;
        }
        public Task<Apiresult<object>> Handle(ImmuneXiugaiCommands request, CancellationToken cancellationToken)
        {
            Apiresult<object> res = new Apiresult<object>();
            var exists = immuneRepo.GetAll().FirstOrDefault(x => x.ImmuneId == request.ImmuneId);
                exists.Feeding_Days = request.Feeding_Days;
                exists.Immune_System = request.Immune_System;
                exists.Immune_Methods = request.Immune_Methods;
                immuneRepo.Update(exists);
                res.Code = ApiEnums.成功;
                res.Message = "已存在，执行修改操作";
            return Task.FromResult(res);
        }
    }
}
